// https://leetcode.cn/problems/number-complement/
// Created by ade on 2022/8/8.
//
#include <iostream>
#include <math.h>

using namespace std;

class Solution {
public:
    // 思路：原来的数+补数4 = n个1
    int findComplement(int num) {
        int count = 0;
        int tmp = num;
        while (num) {
            count++;
            num >>= 1;
        }
        return pow(2, count) - tmp - 1;
    }
};

int main() {
    Solution so;
    cout << so.findComplement(5) << endl;
    return 0;
}